#define _CRT_SECURE_NO_WARNINGS 
#include<stdio.h>
int maxProfit(int* prices, int pricesSize) {
    int min = prices[0];
    int i = 0;
    int max = 0;
    int maxi, mini;
    if (pricesSize <= 2)
    {
        if (prices[1] < min)
            return 0;
        else
        {
            return prices[1] - min;
        }
    }
    for (i = 1; i < pricesSize; i++)
    {
        if (prices[i] < min)
        {
            min = prices[i];
            mini = i;
            continue;
        }
        if (max < (prices[i] - min))
        {
            max = prices[i] - min;
            maxi = i;
        }
        if (mini < maxi)
        {
            maxi = prices[i] - min;
        }
        else {
            maxi = 0;
        }
        return maxi;
    }
}